package com.qidian.mespro.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.qidian.mespro.mapper.WorkflowMapper;
import com.qidian.mespro.service.WorkflowService;
import com.qidianit.mes.pojo.Result;
import com.qidianit.mes.pojo.pro.Workflow;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @ Description:
 * @ Author: DuYaTao
 * @ Date: 2025/9/18 - 18:59
 */
@Service
public class WorkflowServiceImpl implements WorkflowService {

    @Autowired
    private WorkflowMapper workflowMapper;

    @Override
    public Result<List<Workflow>> batchDelete(Integer[] ids) {
        return workflowMapper.batchDelete(ids) > 0 ? Result.success() : Result.error("批量删除失败");
    }

    @Override
    public Result<PageInfo<Workflow>> selectList(Workflow workflow, int page, int size) {
        PageHelper.startPage(page,size);
        List<Workflow> workflows = workflowMapper.selectList(workflow);
        return Result.success(new PageInfo<>(workflows));
    }

    @Override
    public Result<Workflow> selectByWorkflowCode(String code) {
        return Result.success(workflowMapper.selectByWorkflowCode(code));
    }

    @Override
    public Result<Workflow> addWorkflow(Workflow workflow) {
        return workflowMapper.insertWorkflow(workflow) == 1 ? Result.success() : Result.error("添加失败");
    }

    @Override
    public Result<Workflow> updateWorkflow(Workflow workflow) {
        return workflowMapper.updateWorkflow(workflow) ==1 ? Result.success() : Result.error("修改失败");
    }

    @Override
    public Result<Workflow> deleteWorkflow(Integer id) {
        return workflowMapper.deleteById(id) == 1 ? Result.success() : Result.error("删除失败");
    }
}
